/**
 * Copyright (c) 2010
 * Bert Young. UESTC. 
 */

#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include <unistd.h>
#include <fcntl.h>
#include "Log.h"

Logger::Logger( const char * filename ) : fd(-1)
{
	fd = ::open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
	if ( -1 == fd )
		abort();
}

Logger::~Logger( )
{
	if ( fd >= 0 )
		::close(fd);
}

void Logger::debug(const char * fmt, ...)
{
	char buf[128];
	va_list ap;
	va_start(ap, fmt);
	int nBytes = vsnprintf(buf, sizeof(buf), fmt, ap);
	if ( nBytes > 0 )
		write(fd, buf, nBytes);
}

